var gridOptions = {};

$(function(){
	//初始化数据表格
	initGrid();
});


function initGrid(){
	//表格参数
	gridOptions = {
	    url: gateway + app_admin + "/${objName}/index/data",
	    tableId: "data-grid", // grid ID
	    queryFormId: "query-form", // grid ID
	    toolbarId: "toolbar", // toolbar
	    params: {},// 查询默认值
	    modalName: "Dict",
	    columns: [{
	    	checkbox: true,
		},
		<#list columns as k>
		{
			field: '${k.attrname}', 
			title: '${k.columnName}'
		},
		</#list>
		{
		    title: '操作',
		    align: 'center',
		    formatter: function(value, row, index) {
		        var actions = [];
		        actions.push('<a class="btn btn-success btn-xs resource" href="javascript:void(0);" res="${objName}.update" onclick="edit(\'' + row.<#list pk as p>${p.attrname}</#list> + '\')"><i class="fa fa-edit"> </i>'+getI18NWords('sys.common.button.edit')+'</a> ');
		        actions.push('<a class="btn btn-danger btn-xs resource" href="javascript:void(0);" res="${objName}.del" onclick="del(\'' + row.<#list pk as p>${p.attrname}</#list> + '\')"><i class="fa fa-remove"> </i>'+getI18NWords('sys.common.button.delete')+'</a> ');
		        return actions.join('');
		    }
		}]
	};
	$.table.init(gridOptions);
}

function add(){
	$.modal.open(getI18NWords('sys.common.button.add'),domain + '/modules/project/${objName}/${objName}Edit.html',function(){
		$.table.refresh(gridOptions);
	});
}

function edit(key){
	$.modal.open(getI18NWords('sys.common.title.window.edit'),domain + '/modules/project/${objName}/${objName}Edit.html?key='+key,function(){
		$.table.refresh(gridOptions);
	});
}

function del(key){
	$.modal.confirm(getI18NWords('sys.common.tip.delete'),function(){
		$.operate.post(gateway + app_authority + '/${objName}/del?keys='+key, {} , function(result) {
			if($.modal.tip(result)){
				$.table.refresh(gridOptions);
			}
		});
	});
}